﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using Medianamik.Core.Profile;

namespace Medianamik.UI.Web.UserControls
{
    public partial class UserBox : BaseUserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        /// <summary>
        /// Logout de Médianamik. Retourner à la page de login.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnLogout_Click(object sender, EventArgs e)
        {
            FormsAuthentication.SignOut();
            Session.Clear();
            Session.Abandon();
            Response.Redirect("/Medianamik/Login.aspx");
        }

        public string ModifyURL
        {
            get
            {
                return "/medianamik/modalwindows/modifypasswordwindow.aspx?ReturnURL=" + Server.UrlEncode(Request.RawUrl);
            }
        }

		public UserProfile Profile
		{
			get
			{
				return (UserProfile)HttpContext.Current.Profile;
			}
		}

		protected string FullName
		{
			get
			{
                return Session["Profile.FullName"] as string
                    ?? (string)(Session["Profile.FullName"] = string.IsNullOrEmpty(Profile.FullName)
                                                     ? Page.User.Identity.Name
                                                     : Profile.FullName);
			}
		}

        protected string LastLoginDate
        {
            get
            {
                return Session["Profile.LastLoginDate"] as string
                    ?? (string)(Session["Profile.LastLoginDate"] = Profile.LastLoginDate.ToString()) ;
            }
        }
	}
}